package be.kuleuven.cs.mop.domain.repositories.impl;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import be.kuleuven.cs.mop.domain.repositories.Repository;



/**
 * Default implementation of the {@link Repository} interface
 */
public class RepositoryImpl<T> extends HashSet<T> implements Repository<T> {
	private static final long serialVersionUID = 1L;
	
	
	
	@Override
	public boolean add(final T e) {
		if (e == null)
			throw new NullPointerException("element == NULL");
		
		synchronized (this) { return super.add(e); }
	}
	
	@Override
	public boolean contains(final Object o) {
		if (o == null)
			throw new NullPointerException("element == NULL");
		
		synchronized (this) { return super.contains(o); }
	}
	
	@Override
	public List<T> getList() {
		synchronized (this) { return new ArrayList<T>(this); }
	}
	
	@Override
	public boolean remove(final Object o) {
		if (o == null)
			throw new NullPointerException("element == NULL");
		
		synchronized (this) { return super.remove(o); }
	}
	
}